package com.xlh.wjdcserver.controller;

import com.common.result.Result;
import com.property.dto.QuestionAddDTO;
import com.property.dto.QuestionDelDTO;
import com.property.dto.QuestionUpDTO;
import com.property.entity.Question;
import com.xlh.wjdcserver.service.QuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "问卷问题接口")
@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @PostMapping("/addQuestion")
    @Operation(summary = "添加问卷问题")
    public Result addQuestion(@RequestBody List<QuestionAddDTO> questionsAndOptions) {
        questionService.addQuestion(questionsAndOptions);
        return Result.ok();
    }

    @PostMapping("/updateQuestion")
    @Operation(summary = "更新问卷问题")
    public Result updateQuestion(@RequestBody QuestionUpDTO questionUpDTO) {
        questionService.updateQuestion(questionUpDTO);
        return Result.ok();
    }

    @DeleteMapping("/deleteQuestion")
    @Operation(summary = "删除问卷问题")
    public Result deleteQuestion(@RequestBody List<QuestionDelDTO> questionIds) {
        questionService.deleteQuestion(questionIds);
        return Result.ok();
    }

    @GetMapping("/listQuestionsByQid/{qid}")
    @Operation(summary = "查询问卷所有问题")
    public Result<List<QuestionAddDTO>> listQuestionsByQid(@PathVariable String qid) {
        List<QuestionAddDTO> list = questionService.listQuestionsByQid(qid);
        return Result.ok(list);
    }

}
